package com.xunyin.enums;

/**
 * @author jthong
 * @Description:继电器指令（开）
 * @Version 1.0.0
 * @Date 2020/06/05 14:39
 */
public enum RelayOnCmdEnum {
    /***
     * 继电器端口1(空调)
     */
    RELAY_ADDR_1(1, "01050000FF008C3A"),

    /***
     * 继电器端口2（灯）
     */
    RELAY_ADDR_2(2, "01050001FF00DDFA"),

    /***
     * 继电器端口3（插座）
     */
    RELAY_ADDR_3(3, "01050002FF002DFA"),

    /***
     * 继电器端口4
     */
    RELAY_ADDR_4(4, "01050003FF007C3A");

    private final String name;
    private final int value;

    RelayOnCmdEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static RelayOnCmdEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (RelayOnCmdEnum e : RelayOnCmdEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static RelayOnCmdEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + RelayOnCmdEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (RelayOnCmdEnum e : RelayOnCmdEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
